﻿<cfsilent>
	<cfscript>
		
		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		
		termId = event.getArg("TermID");
		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");
		
		taskId = event.getArg("TSK");
		taskType = event.getArg("TT");
		
		targetWeek = event.getArg("W");

		weekDay = event.getArg("wkday");
		lectureId = event.getArg("lec");
		cells = event.getArg("n");

		passArgs = structNew();
		structInsert( passArgs, "TSK", taskId );
		structInsert( passArgs, "TT", taskType );
		structInsert( passArgs, "TID", termId );
		structInsert( passArgs, "W", targetWeek );
		
		structInsert( passArgs, "wkday", weekDay );
		structInsert( passArgs, "lec", lectureId );
		structInsert( passArgs, "n", cells );
		
		switch(taskType){
			case "C":
				sql = "SELECT 
							t_course.course_name, 
							t_teacher.tch_name, 
							a.cr_type, 
							a.task_chooesd, 
							a.campus_id 
						FROM 
							t_common_task a 
							INNER JOIN t_course ON t_course.cid = a.cid 
							INNER JOIN t_teacher ON t_teacher.tch_id = a.tch_id 
						WHERE 
							a.tsk_id = :taskId ";
				break;

			case "P":
				sql = "SELECT 
							t_course.course_name, 
							t_teacher.tch_name, 
							a.cr_type, 
							a.task_chooesd, 
							a.campus_id 
						FROM 
							t_task a 
							INNER JOIN t_course ON t_course.cid = a.cid 
							INNER JOIN t_teacher ON t_teacher.tch_id = a.tch_id 
						WHERE 
							a.tsk_id = :taskId ";
				break;
			
			case "R":
				sql = "SELECT 
							t_course.course_name, 
							t_teacher.tch_name, 
							a.cr_type, 
							a.task_chooesd, 
							a.campus_id 
						FROM 
							t_reopen_task a 
							INNER JOIN t_course ON t_course.cid = a.cid 
							INNER JOIN t_teacher ON t_teacher.tch_id = a.tch_id 
						WHERE 
							a.tsk_id = :taskId ";
				break;
			
			case "T":
				sql = "SELECT 
							t_course.course_name, 
							t_teacher.tch_name, 
							a.cr_type, 
							a.task_chooesd, 
							a.campus_id 
						FROM 
							t_sport_task a 
							INNER JOIN t_course ON t_course.cid = a.cid 
							INNER JOIN t_teacher ON t_teacher.tch_id = a.tch_id 
						WHERE 
							a.tsk_id = :taskId ";
				break;
		}
		
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
		rs_task = queryObj.execute( sql=sql ).getResult();
		
		/* 查询可用教室及教学楼 */
		cellStart = mathAdvice.convertLectureIdxToCellStart(lectureId);
		cellEnd = cellStart + cells -1;
		
		courseSize = rs_task.task_chooesd;
		clsroomType = rs_task.cr_type;
		campusId = rs_task.campus_id;
		
		buildId = event.getArg("BID");
		conHSQL = "";

		if ( len(buildId) ) {
			campusId = event.getArg("CAPID");
			conHSQL = " and t_building.b_id = '" & buildId & "' ";
		}
		sql = "SELECT 
					a.cr_id, 
					a.classroom, 
					a.sits_course, 
					a.cr_floor, 
					t_classroom_type.cr_type_name, 
					t_campus.campus_name, 
					t_building.b_name 
				FROM 
					t_classroom a 
					INNER JOIN t_classroom_type ON t_classroom_type.cr_type = a.cr_type 
					INNER JOIN t_campus ON t_campus.campus_id = a.campus_id 
					INNER JOIN t_building ON t_building.b_id = a.b_id 
				WHERE 
					SUBSTR(a.cr_usage, 2, 1) = '1' 
					AND 
					(a.sits_course > :courseSize OR a.sits_course = :courseSize) 
					AND 
					t_classroom_type.cr_type = :clsroomType 
					AND 
					t_campus.campus_id = :campusId " & conHSQL & " 
					AND 
					NOT EXISTS( 
						SELECT 1 FROM t_clsroom_timetable b 
						WHERE 
							   a.cr_id = b.cr_id 
							   AND 
							   b.term_id = :termId 
							   AND 
							   b.wdidx = :weekDay 
							   AND 
							   NOT(b.cellidx + b.cellrelay - 1 < :cellStart OR b.cellidx > :cellEnd) 
							   AND 
							   (SUBSTR(b.widx, " & targetWeek & ", 1) = '1')
					) 
				ORDER BY 
					a.sits_course ASC, a.classroom ASC ";
					
		queryObj = new query( datasource=application.dnsSlave, maxRows=15 );
		queryObj.addParam( name="courseSize", value=courseSize, cfsqltype="cf_sql_integer" );
		queryObj.addParam( name="clsroomType", value=clsroomType, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="campusId", value=campusId, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="weekDay", value=weekDay, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="cellStart", value=cellStart, cfsqltype="cf_sql_integer" );
		queryObj.addParam( name="cellEnd", value=cellEnd, cfsqltype="cf_sql_integer" );
		rs_room = queryObj.execute( sql=sql ).getResult();

		sql = "SELECT 
					DISTINCT t_building.b_id, 
					t_building.b_name, 
					t_building.b_floors, 
					a.campus_id 
				FROM 
					t_classroom a 
					INNER JOIN t_building ON t_building.b_id = a.b_id 
				WHERE 
					SUBSTR(A.CR_USAGE, 2, 1) = '1' 
					AND 
					(a.sits_course > :courseSize OR a.sits_course = :courseSize) 
					AND 
					a.cr_type = :clsroomType 
					AND 
						NOT EXISTS(
							SELECT 1 FROM t_clsroom_timetable b 
							WHERE 
								   a.cr_id = b.cr_id 
								   AND 
								   b.term_id = :termId 
								   AND 
								   b.wdidx = :weekDay 
								   AND 
								   NOT(b.cellidx + b.cellrelay - 1 < :cellStart OR b.cellidx > :cellEnd) 
								   AND 
								   (SUBSTR(b.widx, " & targetWeek & ", 1) = '1')
						)
				ORDER BY 
					t_building.b_id ";
					
		queryObj = new query( datasource=application.dnsSlave, maxRows=15 );
		queryObj.addParam( name="courseSize", value=courseSize, cfsqltype="cf_sql_integer" );
		queryObj.addParam( name="clsroomType", value=clsroomType, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="weekDay", value=weekDay, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="cellStart", value=cellStart, cfsqltype="cf_sql_integer" );
		queryObj.addParam( name="cellEnd", value=cellEnd, cfsqltype="cf_sql_integer" );
		rs_building = queryObj.execute( sql=sql ).getResult();
		
		event.setArg("pageTitle", "教学任务安排 - 补课向导 - " & rs_task.course_name );
		
		currentTab = event.getArg("TabID", "labClassroom");
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('taskTempChange')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">临时性调停课</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 card"></i>临时补课向导 <cfoutput>#rs_task.course_name#</cfoutput>-<cfoutput>#rs_task.tch_name#</cfoutput> 
				</h2>
			</div>
		</div>
	</div>
</div>

<!--- 加载导航菜单 --->
<!-- stepMenu-->
<cfoutput>#event.getArg("stepMenu")#</cfoutput>
<!--/stepMenu-->

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				
				<div class="UItab">
					<div class="tabLables">
						<cfif rs_building.recordCount>
							<span <cfif currentTab eq "labBuilding">class="active"</cfif> id="labBuilding" tabTarget="Building">教学区域</span>
						</cfif>
						<span <cfif currentTab eq "labClassroom">class="active"</cfif> id="labClassroom" tabTarget="Classroom">教室</span>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
					
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
								
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					
					// -->
					//]]>
				</script>
				
				<cfif rs_building.recordCount>
				
					<div id="Building" class="tabContent">
						
						<div class="noticeBlock">
							<h3>选择教学区域</h3>
							<p><span class="img icon16x16 message"></span>如果需要指定补课区域, 请在这里进行选择</p>
							<hr/>
						</div>
						
						<div class="clearfix">
							<div class="UICardTable">
                                <cfloop query="rs_building">
									<cfset structInsert(passArgs, "BID", rs_building.b_id, true) />
									<cfset structInsert(passArgs, "CAPID", rs_building.campus_id, true) />
									<dl>
										<dt>
											<a href="<cfoutput>#buildURL('taskChangeWizardAppendClassroom', passArgs)#</cfoutput>">
												<em class="building"><!--imgholder--></em>
												<dd>
													<h3><cfoutput>#rs_building.b_name#</cfoutput></h3>
													<div><cfoutput>#dictAdvice.getBuildingFloorSummary(rs_building.b_floors)#</cfoutput></div>
												</dd>
											</a>
										</dt>
									</dl>
											
								</cfloop>
								<!--- 移出楼宇参数 --->
								<cfset structDelete( passArgs, "BID", false ) />
								<cfset structDelete( passArgs, "CAPID", false ) />
							</div>
						</div>

					</div>
					
				</cfif>
				
				<div id="Classroom" class="tabContent">
					
					<div class="noticeBlock">
						<h3>可用教室清单</h3>
						<p><span class="img icon16x16 message"></span>下面是符合教学班补课条件的教室清单, 你也可以选择其他的教室类别</p>
						<hr/>
					</div>
					
					<cfif rs_room.recordCount>
							
							<cfset row = 0 />
							<table class="UIEditable">
								<thead>
									<tr>
										<td width="18"></td>
										<td>教室</td>
										<td width="80">所在校区</td>
										<td>教室类别</td>
										<td width="60" align="left">座位数</td>
										<td>位置</td>
										<td width="18"></td>
									</tr>
								</thead>
								<tbody>
                                    <cfloop query="rs_room">
										<cfset row++ />
										<cfset structInsert(passArgs, "CLSROOM", rs_room.cr_id, true) />
										<tr class="editRows">
											<td class="index"><cfoutput>#row#</cfoutput></td>
											<td><cfoutput>#rs_room.classroom#</cfoutput></td>
											<td><cfoutput>#rs_room.campus_name#</cfoutput></td>
											<td><cfoutput>#rs_room.cr_type_name#</cfoutput></td>
											<td><span class="numeric"><cfoutput>#rs_room.sits_course#</cfoutput></span></td>
											<td><cfoutput>#rs_room.b_name#</cfoutput> <cfoutput>#dictAdvice.getFloorString( rs_room.cr_floor )#</cfoutput></td>
											<td><a title="使用该教室" class="stat examer" href="<cfoutput>#buildURL('taskChangeWizardAppendSign', passArgs)#</cfoutput>"></a></td>
										</tr>
									</cfloop>
									<!--- 移出教室参数 --->
									<cfset structDelete( passArgs, "CLSROOM", false ) />
								</tbody>
							</table>
							
						<cfelse>
							
							<div class="systemNotice">
								<p>没有适合的教室</p>
							</div>
							
					</cfif>

				</div>

			</div>
		</li>
	</ul>
</div>